
package my.gui;

import my.gui.Log;
import my.gui.GraficoArbol;
//import com.mysql.jdbc.log.Log;
import java.sql.SQLException;
import java.util.*;
import java.util.ArrayList;

public class gui extends javax.swing.JFrame {

    public static String usuario, password, nombrebd, columna, datosDiscretizar, tabla;
    ArrayList columna_arbol = new ArrayList();
    ArrayList valor_columna_arbol = new ArrayList();
    ArrayList valores_decision= new ArrayList();
    HashMap map = new HashMap();
    public static Log log = new Log();
    public static String c = "", aux = "";
    ArrayList arbolTexto = new ArrayList();
    public static ArrayList arbolgrafico = new ArrayList();
    static int nivel=0, contAst=0;
    static String padre = "", result = "";

    /** Creates new form gui */
    public gui() {
        initComponents();
        NombreBD.setText("com");
        UsuarioBD.setText("root");
        PasswordBD.setText("mysql");
        TablaBD.setText("juego1");
        ColumnaBD.setText("play");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFrame1 = new javax.swing.JFrame();
        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        buttonGroup4 = new javax.swing.ButtonGroup();
        buttonGroup5 = new javax.swing.ButtonGroup();
        buttonGroup6 = new javax.swing.ButtonGroup();
        buttonGroup7 = new javax.swing.ButtonGroup();
        buttonGroup8 = new javax.swing.ButtonGroup();
        buttonGroup9 = new javax.swing.ButtonGroup();
        buttonGroup10 = new javax.swing.ButtonGroup();
        buttonGroup11 = new javax.swing.ButtonGroup();
        buttonGroup12 = new javax.swing.ButtonGroup();
        buttonGroup13 = new javax.swing.ButtonGroup();
        buttonGroup14 = new javax.swing.ButtonGroup();
        buttonGroup15 = new javax.swing.ButtonGroup();
        buttonGroup16 = new javax.swing.ButtonGroup();
        buttonGroup17 = new javax.swing.ButtonGroup();
        buttonGroup18 = new javax.swing.ButtonGroup();
        buttonGroup19 = new javax.swing.ButtonGroup();
        buttonGroup20 = new javax.swing.ButtonGroup();
        buttonGroup21 = new javax.swing.ButtonGroup();
        buttonGroup22 = new javax.swing.ButtonGroup();
        buttonGroup23 = new javax.swing.ButtonGroup();
        buttonGroup24 = new javax.swing.ButtonGroup();
        buttonGroup25 = new javax.swing.ButtonGroup();
        buttonGroup26 = new javax.swing.ButtonGroup();
        buttonGroup27 = new javax.swing.ButtonGroup();
        buttonGroup28 = new javax.swing.ButtonGroup();
        buttonGroup29 = new javax.swing.ButtonGroup();
        buttonGroup30 = new javax.swing.ButtonGroup();
        buttonGroup31 = new javax.swing.ButtonGroup();
        Titulo2 = new javax.swing.JLabel();
        DatoBD = new javax.swing.JLabel();
        DatoUsuario = new javax.swing.JLabel();
        DatoPassword = new javax.swing.JLabel();
        PanelGral = new javax.swing.JTabbedPane();
        PanelDatos = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        TextoDatos = new javax.swing.JTextArea();
        PanelArbol = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        TextoArbol = new javax.swing.JTextArea();
        BotonGrafico = new javax.swing.JButton();
        PanelLog = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        TextoLog = new javax.swing.JTextArea();
        Titulo1 = new javax.swing.JLabel();
        Inform1 = new javax.swing.JLabel();
        Inform2 = new javax.swing.JLabel();
        Inform3 = new javax.swing.JLabel();
        DatoColumna = new javax.swing.JLabel();
        Discretizacion = new javax.swing.JLabel();
        BotonOK = new javax.swing.JButton();
        Promedio = new javax.swing.JRadioButton();
        Especifico = new javax.swing.JRadioButton();
        SinDiscretizar = new javax.swing.JRadioButton();
        UsuarioBD = new javax.swing.JTextField();
        NombreBD = new javax.swing.JTextField();
        ColumnaBD = new javax.swing.JTextField();
        PasswordBD = new javax.swing.JPasswordField();
        jScrollPane4 = new javax.swing.JScrollPane();
        DatosDiscretizacion = new javax.swing.JTextArea();
        DatoTabla = new javax.swing.JLabel();
        TablaBD = new javax.swing.JTextField();

        jFrame1.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
        jFrame1.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jFrame1Layout.setVerticalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Algoritmo J48   -    A. Aranda (54210), F. Cardozo (51300), L. Figueredo (51160)");
        setAlwaysOnTop(true);
        setName("VentanaPrincipal"); // NOI18N

        Titulo2.setFont(new java.awt.Font("Tahoma", 1, 14));
        Titulo2.setForeground(new java.awt.Color(102, 102, 255));
        Titulo2.setText("Conexion a la Base de Datos");

        DatoBD.setText("Nombre de la Base de Datos:");

        DatoUsuario.setText("Nombre de Usuario:");

        DatoPassword.setText("Contraseña:");

        PanelGral.setBackground(new java.awt.Color(153, 153, 153));
        PanelGral.setAutoscrolls(true);

        TextoDatos.setColumns(20);
        TextoDatos.setEditable(false);
        TextoDatos.setRows(5);
        jScrollPane1.setViewportView(TextoDatos);

        javax.swing.GroupLayout PanelDatosLayout = new javax.swing.GroupLayout(PanelDatos);
        PanelDatos.setLayout(PanelDatosLayout);
        PanelDatosLayout.setHorizontalGroup(
            PanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelDatosLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE)
                .addContainerGap())
        );
        PanelDatosLayout.setVerticalGroup(
            PanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelDatosLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE)
                .addContainerGap())
        );

        PanelGral.addTab("Datos de la Tabla", PanelDatos);

        jScrollPane2.setAutoscrolls(true);

        TextoArbol.setColumns(20);
        TextoArbol.setEditable(false);
        TextoArbol.setRows(5);
        jScrollPane2.setViewportView(TextoArbol);

        BotonGrafico.setText("Ver Grafico del Arbol");
        BotonGrafico.setEnabled(false);
        BotonGrafico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonGraficoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout PanelArbolLayout = new javax.swing.GroupLayout(PanelArbol);
        PanelArbol.setLayout(PanelArbolLayout);
        PanelArbolLayout.setHorizontalGroup(
            PanelArbolLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelArbolLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanelArbolLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE)
                    .addComponent(BotonGrafico, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        PanelArbolLayout.setVerticalGroup(
            PanelArbolLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelArbolLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 513, Short.MAX_VALUE)
                .addGap(11, 11, 11)
                .addComponent(BotonGrafico)
                .addContainerGap())
        );

        PanelGral.addTab("Arbol Generado", PanelArbol);

        jScrollPane3.setAutoscrolls(true);

        TextoLog.setColumns(20);
        TextoLog.setEditable(false);
        TextoLog.setRows(5);
        jScrollPane3.setViewportView(TextoLog);

        javax.swing.GroupLayout PanelLogLayout = new javax.swing.GroupLayout(PanelLog);
        PanelLog.setLayout(PanelLogLayout);
        PanelLogLayout.setHorizontalGroup(
            PanelLogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelLogLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE)
                .addContainerGap())
        );
        PanelLogLayout.setVerticalGroup(
            PanelLogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelLogLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE)
                .addContainerGap())
        );

        PanelGral.addTab("Log", PanelLog);

        Titulo1.setFont(new java.awt.Font("Tahoma", 1, 24));
        Titulo1.setForeground(new java.awt.Color(102, 102, 255));
        Titulo1.setText("Implementacion del Algoritmo J48");

        Inform1.setText("Ingrese la informacion solicitada referente a la Base de Datos y");
        Inform1.setFocusable(false);

        Inform2.setText("presione 'OK' para que la informacion obtenida de la misma sea");

        Inform3.setText("procesada. Los resultados obtenidos seran mostrados en el panel.");

        DatoColumna.setText("Columna:");

        Discretizacion.setFont(new java.awt.Font("Tahoma", 1, 12));
        Discretizacion.setText("Tipo de Discretizacion de Datos Numericos:");

        BotonOK.setText("OK");
        BotonOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonOKActionPerformed(evt);
            }
        });

        buttonGroup1.add(Promedio);
        Promedio.setText("Promedio de los Valores Dados");
        Promedio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PromedioActionPerformed(evt);
            }
        });

        buttonGroup1.add(Especifico);
        Especifico.setText("Valores Especificos:");
        Especifico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EspecificoActionPerformed(evt);
            }
        });

        buttonGroup1.add(SinDiscretizar);
        SinDiscretizar.setSelected(true);
        SinDiscretizar.setText("Sin Discretizacion");
        SinDiscretizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SinDiscretizarActionPerformed(evt);
            }
        });

        UsuarioBD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                UsuarioBDActionPerformed(evt);
            }
        });

        NombreBD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NombreBDActionPerformed(evt);
            }
        });

        ColumnaBD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ColumnaBDActionPerformed(evt);
            }
        });

        PasswordBD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PasswordBDActionPerformed(evt);
            }
        });

        DatosDiscretizacion.setColumns(20);
        DatosDiscretizacion.setRows(3);
        DatosDiscretizacion.setText("columna, valor; ...");
        DatosDiscretizacion.setEnabled(false);
        jScrollPane4.setViewportView(DatosDiscretizacion);

        DatoTabla.setText("Tabla:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(Titulo1)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(Titulo2)
                                .addGap(182, 182, 182))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(16, 16, 16)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                .addComponent(Inform1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(Inform2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(Inform3))
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                .addGroup(layout.createSequentialGroup()
                                                    .addGap(70, 70, 70)
                                                    .addComponent(jScrollPane4))
                                                .addComponent(Discretizacion, javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(BotonOK))))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(55, 55, 55)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(10, 10, 10)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(Especifico)
                                                    .addComponent(SinDiscretizar)
                                                    .addComponent(Promedio)))
                                            .addComponent(DatoBD, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(DatoUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(DatoPassword, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
                                            .addComponent(DatoTabla)
                                            .addComponent(DatoColumna, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                .addComponent(UsuarioBD, javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(NombreBD, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE))
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                .addComponent(TablaBD, javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(PasswordBD, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE))
                                            .addComponent(ColumnaBD, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(22, 22, 22)))
                                .addGap(39, 39, 39)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(PanelGral, javax.swing.GroupLayout.PREFERRED_SIZE, 665, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(34, 34, 34))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addComponent(Titulo1)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(Titulo2)
                        .addGap(7, 7, 7)
                        .addComponent(Inform1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Inform2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Inform3)
                        .addGap(18, 18, 18)
                        .addComponent(DatoBD)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(NombreBD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(DatoUsuario)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(UsuarioBD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(DatoPassword)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(PasswordBD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(DatoTabla)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(TablaBD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(DatoColumna)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ColumnaBD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(56, 56, 56)
                        .addComponent(Discretizacion)
                        .addGap(8, 8, 8)
                        .addComponent(SinDiscretizar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Promedio)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Especifico)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                        .addComponent(BotonOK))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(PanelGral, javax.swing.GroupLayout.DEFAULT_SIZE, 597, Short.MAX_VALUE)))
                .addGap(37, 37, 37))
        );

        PanelGral.getAccessibleContext().setAccessibleName("Datos de la Tabla");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BotonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonOKActionPerformed
        // TODO add your handling code here:
        usuario = UsuarioBD.getText();
        nombrebd = NombreBD.getText();
        password = PasswordBD.getText();
        columna = ColumnaBD.getText();
        tabla = TablaBD.getText();
        UsuarioBD.setEnabled(false);
        NombreBD.setEnabled(false);
        PasswordBD.setEnabled(false);
        ColumnaBD.setEnabled(false);
        BotonGrafico.setEnabled(true);
        TablaBD.setEnabled(false);
        BotonOK.setEnabled(false);

        if (Especifico.isEnabled() == true){
            datosDiscretizar = DatosDiscretizacion.getText();
            datosDiscretizar = datosDiscretizar.trim();

            for (int i=0; i< datosDiscretizar.length(); i++){
                //parsear el string
                c = datosDiscretizar.substring(i, i+1);

                if ((c.compareTo(" ") == 0) || (c.compareTo("\n") == 0) || (c.compareTo("\t") == 0)){
                    //ignorar
                } else
                if (c.compareTo(",") == 0){
                    DataBase.nom_col_dis.add(aux);
                    aux = "";
                } else if (c.compareTo(";") == 0){
                    DataBase.val_col_dis.add(aux);
                    aux = "";
                } else {
                    aux = aux.concat(c);
                }
            }
            System.out.println("Columnas: " + DataBase.nom_col_dis + "\nValores: " + DataBase.val_col_dis);
        }

        Promedio.setEnabled(false);
        Especifico.setEnabled(false);
        SinDiscretizar.setEnabled(false);
        DatosDiscretizacion.setEnabled(false);

	DataBase.columna_decision=columna;
	DataBase.tabla_d = tabla;
        //Cargar los datos de la BD para mostrar en el Panel de Datos
        TextoDatos.setText("\n  Base de Datos: ");
        TextoDatos.append(nombrebd);
        TextoDatos.append("\n  Usuario: ");
        TextoDatos.append(usuario);
        TextoDatos.append("\n\n  Información extraida de la Base de Datos: \n");

        DataBase datos = new DataBase();
        datos.Conectar(nombrebd,usuario, password);

        try{
            datos.getNombresColumnas();
            tree.generar_arbol(columna_arbol, valores_decision, 1.0, arbolTexto,0);
            //map = datos.ParseoDB(columna_arbol,valor_columna_arbol);
            //valores_decision=datos.getCantidadValores(columna_arbol, valor_columna_arbol);
            //System.out.println(tree.calcular_nodo(map,valores_decision));
            System.out.println(arbolTexto);
            datos.getValoresPantalla();
        }
        catch(SQLException e){
            System.out.println("Error al parsear: " + e);
        }
        TextoDatos.append("      ");
        for(int i = 0; i < datos.data.size(); i++){
            TextoDatos.append(datos.data.get(i).toString());
        }

        //Generar el Log
        TextoLog.setText("");
        //TextoLog.append("  Base de Datos analizada: " + nombrebd + "\n");
        for(int i = 0; i < log.datosLog.size(); i++){
            TextoLog.append(log.datosLog.get(i).toString());
        }

        TextoArbol.setText("\n  Traduccion del Arbol Generado a Reglas:\n");
        TextoArbol.append(arbolReglas());

        datos.Desconectar();
        TextoLog.append("  " + new Date() + "\tTermino de la Ejecucion\n");
    }//GEN-LAST:event_BotonOKActionPerformed

    private void PromedioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PromedioActionPerformed
        // TODO add your handling code here:
        if (Promedio.isSelected() == true) {
	    DataBase.get_promedio = 1;
            DatosDiscretizacion.setEnabled(false);
        } else {
	    DataBase.get_promedio = 0;
            DatosDiscretizacion.setEnabled(true);
        }
    }//GEN-LAST:event_PromedioActionPerformed

    private void EspecificoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EspecificoActionPerformed
        // TODO add your handling code here:
        if (Especifico.isSelected() == true) {
	    DataBase.get_promedio = 0;
            DatosDiscretizacion.setEnabled(true);
        } else {
            DatosDiscretizacion.setEnabled(false);
        }
    }//GEN-LAST:event_EspecificoActionPerformed

    private void SinDiscretizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SinDiscretizarActionPerformed
        // TODO add your handling code here:
        if (SinDiscretizar.isSelected() == true) {
	    DataBase.get_promedio = 0;
            DatosDiscretizacion.setEnabled(false);
        } else {
            DatosDiscretizacion.setEnabled(true);
        }
    }//GEN-LAST:event_SinDiscretizarActionPerformed

    private void UsuarioBDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_UsuarioBDActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_UsuarioBDActionPerformed

    private void NombreBDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NombreBDActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_NombreBDActionPerformed

    private void ColumnaBDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ColumnaBDActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ColumnaBDActionPerformed

    private void PasswordBDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PasswordBDActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_PasswordBDActionPerformed

    private void BotonGraficoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonGraficoActionPerformed
        // TODO add your handling code here:
        arbolgrafico=GraficoArbol.parseaAbol(arbolTexto);
        System.out.println("Arbol P: " + arbolTexto);
        BotonGrafico.setEnabled(false);
        GraficoArbol g=new GraficoArbol(arbolgrafico);
        g.setAlwaysOnTop(true);
        g.setVisible(true);
    }//GEN-LAST:event_BotonGraficoActionPerformed


    public String arbolReglas() {
        //System.out.println("Arbol Profundidad: " + arbolTexto);
        padre = arbolTexto.get(0).toString();

        for (int i = 1; i < arbolTexto.size(); i++){

            if (arbolTexto.get(i-1).toString().equals("@")){
                padre = arbolTexto.get(i - 2).toString();
                nivel = Integer.valueOf(arbolTexto.get(i).toString());
                for (int j=0; j<nivel; j++)
                    result = result.concat("\n        ");
                if (nivel == 0)
                    result = result.concat("\n");
                result = result.concat("  IF (" + padre);
                if (arbolTexto.get(i + 2).toString().contains("<") == false && arbolTexto.get(i + 2).toString().contains(">") == false)
                    result = result.concat("==");
                result = result.concat(arbolTexto.get(i + 1) + ") THEN");
                for (int j=0; j<nivel; j++)
                    result = result.concat("\n        ");
                if (nivel == 0)
                    result = result.concat("\n");
                result = result.concat("          NODE = " + arbolTexto.get(i + 2));
            }

            if (i >= 2){
                if (arbolTexto.get(i).toString().equals("*")){
                    contAst++;
                    if (i <= (arbolTexto.size() - 2)){
                        if (arbolTexto.get(i + 1).toString().equals("*") == false){
                            nivel = Integer.valueOf(arbolTexto.get(i + 1).toString());
                            if (contAst > 1 && ( arbolTexto.indexOf(nivel)-2 >=0 ))
                                padre = arbolTexto.get(arbolTexto.indexOf(nivel) - 2).toString();
                            for (int j=0; j<nivel; j++)
                                result = result.concat("\n        ");
                            if (nivel == 0)
                                result = result.concat("\n");
                            if ( Integer.valueOf(arbolTexto.get(i+1).toString()) == nivel){
                                result = result.concat("  ELSE IF (" + padre);
                                if (arbolTexto.get(i + 2).toString().contains("<") == false && arbolTexto.get(i + 2).toString().contains(">") == false)
                                    result = result.concat("==");
                                result = result.concat(arbolTexto.get(i + 2) + ") THEN");
                                for (int j=0; j<nivel; j++)
                                    result = result.concat("\n        ");
                                if (nivel == 0)
                                    result = result.concat("\n");
                                result = result.concat("          NODE = " + arbolTexto.get(i + 3));
                            }
                        }
                    }
                }
            }

            if (arbolTexto.get(i).toString().equals("*") == false && arbolTexto.get(i-1).toString().equals("*") == true)
                contAst=0;

        }
        System.out.println(result);
        return result;
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new gui().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BotonGrafico;
    private javax.swing.JButton BotonOK;
    private javax.swing.JTextField ColumnaBD;
    private javax.swing.JLabel DatoBD;
    private javax.swing.JLabel DatoColumna;
    private javax.swing.JLabel DatoPassword;
    private javax.swing.JLabel DatoTabla;
    private javax.swing.JLabel DatoUsuario;
    private javax.swing.JTextArea DatosDiscretizacion;
    private javax.swing.JLabel Discretizacion;
    private javax.swing.JRadioButton Especifico;
    private javax.swing.JLabel Inform1;
    private javax.swing.JLabel Inform2;
    private javax.swing.JLabel Inform3;
    private javax.swing.JTextField NombreBD;
    private javax.swing.JPanel PanelArbol;
    private javax.swing.JPanel PanelDatos;
    private javax.swing.JTabbedPane PanelGral;
    private javax.swing.JPanel PanelLog;
    private javax.swing.JPasswordField PasswordBD;
    private javax.swing.JRadioButton Promedio;
    private javax.swing.JRadioButton SinDiscretizar;
    private javax.swing.JTextField TablaBD;
    private javax.swing.JTextArea TextoArbol;
    private javax.swing.JTextArea TextoDatos;
    public javax.swing.JTextArea TextoLog;
    private javax.swing.JLabel Titulo1;
    private javax.swing.JLabel Titulo2;
    private javax.swing.JTextField UsuarioBD;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup10;
    private javax.swing.ButtonGroup buttonGroup11;
    private javax.swing.ButtonGroup buttonGroup12;
    private javax.swing.ButtonGroup buttonGroup13;
    private javax.swing.ButtonGroup buttonGroup14;
    private javax.swing.ButtonGroup buttonGroup15;
    private javax.swing.ButtonGroup buttonGroup16;
    private javax.swing.ButtonGroup buttonGroup17;
    private javax.swing.ButtonGroup buttonGroup18;
    private javax.swing.ButtonGroup buttonGroup19;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup20;
    private javax.swing.ButtonGroup buttonGroup21;
    private javax.swing.ButtonGroup buttonGroup22;
    private javax.swing.ButtonGroup buttonGroup23;
    private javax.swing.ButtonGroup buttonGroup24;
    private javax.swing.ButtonGroup buttonGroup25;
    private javax.swing.ButtonGroup buttonGroup26;
    private javax.swing.ButtonGroup buttonGroup27;
    private javax.swing.ButtonGroup buttonGroup28;
    private javax.swing.ButtonGroup buttonGroup29;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.ButtonGroup buttonGroup30;
    private javax.swing.ButtonGroup buttonGroup31;
    private javax.swing.ButtonGroup buttonGroup4;
    private javax.swing.ButtonGroup buttonGroup5;
    private javax.swing.ButtonGroup buttonGroup6;
    private javax.swing.ButtonGroup buttonGroup7;
    private javax.swing.ButtonGroup buttonGroup8;
    private javax.swing.ButtonGroup buttonGroup9;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    // End of variables declaration//GEN-END:variables

}
